package map05;

import java.util.HashMap;
import java.util.Map;
public class HashMapDemo01 {
    public static void main(String[] args) {
        HashMap<String, Student> students = new HashMap<>();

        Student s1 = new Student("01", "张三");
        Student s2 = new Student("05", "李四");
        Student s3 = new Student("07", "王五");
        students.put(s1.getSno(),s1);
        students.put(s2.getSno(),s2);
        students.put(s3.getSno(),s3);

        //利用keySet方法遍历
        for(String key:students.keySet()){
            System.out.println(key+" "+students.get(key));
        }
        // 01 Student{name='张三', sno='01'}
        //05 Student{name='李四', sno='05'}
        //07 Student{name='王五', sno='07'}

        //利用entrySet方法遍历
        for(Map.Entry<String,Student> me : students.entrySet()){
            String key = me.getKey();
            Student s = me.getValue();
            System.out.println(key+" "+s.getName());
            //01 张三
            //05 李四
            //07 王五
        }
    }
}
